﻿using System;
using System.Collections.Generic;

namespace FiveMonth.FormWork.Word
{
    /// <summary>
    /// 书签信息
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class BookmarkInfo<T>
    {
        internal BookmarkInfo(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new Exception("书签名称不能为空。");
            }

            Name = name;
        }
        internal BookmarkInfo(string name, Func<T, IList<int>, string> valueFunc) : this(name)
        {
            if (valueFunc == null)
            {
                throw new Exception("书签替换函数不能为空。");
            }

            ValueFunc = valueFunc;
            Type = BookmarkType.String;
        }
        internal BookmarkInfo(string name, Func<T, IList<int>, int> loopCountFunc) : this(name)
        {
            if (loopCountFunc == null)
            {
                throw new Exception("书签循环函数不能为空。");
            }

            LoopCountFunc = loopCountFunc;
            Type = BookmarkType.Loop;
        }
        /// <summary>
        /// 书签名称
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// 书签替换函数
        /// 第一个参数是模板应用的数据，第二个参数是书签所在循环的索引数组，从0开始，返回要替换书签的字符串
        /// </summary>
        public Func<T, IList<int>, string> ValueFunc { get; private set; }

        /// <summary>
        /// 循环书签要循环的集合
        /// 第一个参数是模板应用的数据，第二个参数是书签所在循环的索引数组，从0开始，返回要循环的集合
        /// </summary>
        public Func<T, IList<int>, int> LoopCountFunc { get; private set; }

        public BookmarkType Type { get; internal set; }

        public int Width { get; internal set; }
        public int Height { get; internal set; }
    }
}